package com.kekezu.kppw.data;

import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.tsz.afinal.FinalDb;

import org.apache.http.NameValuePair;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.kekezu.kppw.bean.UserBean;
import com.kekezu.kppw.utils.ConfigInc;
import com.kekezu.kppw.utils.HttpUtils;
import com.kekezu.kppw.utils.StrFormat;

@SuppressWarnings("deprecation")
public class UserData {
	static Intent intent;
	static FinalDb db;

	/**
	 * 用户登录
	 */
	public static String[] userLogin(String strName, String strPwd,
			Context context) {
		String str[] = new String[2];
		db = ConfigInc.getCreateDB(context);
		UserBean user = new UserBean();

		String urlString = ConfigInc.getServiceAdress(context) + "user/login";
		HttpUtils httpUtils = HttpUtils.getInstance();

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("username", strName));
		params.add(new BasicNameValuePair("password", strPwd));

		try {
			String strJson = httpUtils.executeRequest(urlString, params);
			JSONObject jsonObject = new JSONObject(strJson);

			Log.e("strJson", strJson);

			// 对返回的数据进行判断
			if (jsonObject.getString("code").equals("1000")) {
				JSONObject jsonData = new JSONObject(
						jsonObject.getString("data"));
				user.setUid(jsonData.getString("id"));
				user.setUserName(jsonData.getString("name"));
				user.setPassWord(strPwd);
				user.setEmail(jsonData.getString("email"));
				user.setToken(jsonData.getString("token"));
				user.setImage(jsonData.getString("avatar"));
				user.setImPass(jsonData.getString("im_password"));
				db.save(user);
			}

			str[0] = jsonObject.getString("code");
			str[1] = jsonObject.getString("message");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}

	/**
	 * 本地第三方用户登录
	 */
	public static void oauthReLogin(Context context) {
		db = ConfigInc.getCreateDB(context);

		List<UserBean> users = db.findAll(UserBean.class);

		if (users.size() > 0) {
			UserBean user = new UserBean();

			String urlString = ConfigInc.getServiceAdress(context) + "oauth";
			HttpUtils httpUtils = HttpUtils.getInstance();

			List<NameValuePair> params = new ArrayList<NameValuePair>();

			params.add(new BasicNameValuePair("type", users.get(0).getType()));
			params.add(new BasicNameValuePair("uid", users.get(0).getOauthid()));
			params.add(new BasicNameValuePair("nickname", users.get(0)
					.getUserName()));
			params.add(new BasicNameValuePair("sex", users.get(0).getSex()));
			params.add(new BasicNameValuePair("source", "" + 2));

			Log.d("params", users.get(0).getType() + "----"
					+ users.get(0).getOauthid() + "----"
					+ users.get(0).getUserName() + "----"
					+ users.get(0).getSex());

			try {
				String strJson = httpUtils.executeRequest(urlString, params);

				Log.e("oauth", strJson);

				JSONObject jsonObject = new JSONObject(strJson);
				String resString = jsonObject.getString("code");

				// 对返回的数据进行判断
				if (resString.equals("1000")) {
					JSONObject jsonData = new JSONObject(
							jsonObject.getString("data"));

					user.setToken(jsonData.getString("token"));

					db.update(user, "id=" + users.get(0).getId());
				}
			}

			catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public static void ReLogin(Context context) {
		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);
		if (users.size() > 0) {
			if (StrFormat.formatStr(users.get(0).getPassWord())) {
				userReLogin(context);
			} else {
				oauthReLogin(context);
			}
		}
	}

	/**
	 * 本地用户登录
	 */
	public static void userReLogin(Context context) {
		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);
		if (users.size() > 0) {
			UserBean user = new UserBean();

			String urlString = ConfigInc.getServiceAdress(context)
					+ "user/login";
			HttpUtils httpUtils = HttpUtils.getInstance();

			List<NameValuePair> params = new ArrayList<NameValuePair>();

			params.add(new BasicNameValuePair("username", users.get(0)
					.getUserName()));
			params.add(new BasicNameValuePair("password", users.get(0)
					.getPassWord()));

			try {
				String strJson = httpUtils.executeRequest(urlString, params);

				JSONObject jsonObject = new JSONObject(strJson);
				String resString = jsonObject.getString("code");

				// 对返回的数据进行判断
				if (resString.equals("1000")) {
					JSONObject jsonData = new JSONObject(
							jsonObject.getString("data"));

					user.setToken(jsonData.getString("token"));

					db.update(user, "id=" + users.get(0).getId());
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 第三方登录
	 */
	public static String[] oauthLogin(String type, String uid, String nickname,
			String sex, Context context) {
		String str[] = new String[2];
		db = ConfigInc.getCreateDB(context);
		UserBean user = new UserBean();

		String urlString = ConfigInc.getServiceAdress(context) + "oauth";
		HttpUtils httpUtils = HttpUtils.getInstance();

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (type.equals("SinaWeibo")) {
			params.add(new BasicNameValuePair("type", "weibo"));
		} else if (type.equals("QQ")) {
			params.add(new BasicNameValuePair("type", "qq"));
		} else {
			params.add(new BasicNameValuePair("type", "weixinweb"));
		}
		params.add(new BasicNameValuePair("uid", uid));
		params.add(new BasicNameValuePair("nickname", nickname));
		params.add(new BasicNameValuePair("sex", sex));
		params.add(new BasicNameValuePair("source", "" + 2));

		Log.d("params", type + "----" + uid + "----" + nickname + "----" + sex);

		try {
			String strJson = httpUtils.executeRequest(urlString, params);

			JSONObject jsonObject = new JSONObject(strJson);

			str[0] = jsonObject.getString("code");
			str[1] = jsonObject.getString("message");

			// 对返回的数据进行判断
			if (jsonObject.getString("code").equals("1000")) {
				JSONObject jsonData = new JSONObject(
						jsonObject.getString("data"));

				user.setUid(jsonData.getString("uid"));
				user.setUserName(nickname);
				user.setOauthid(uid);
				if (type.equals("SinaWeibo")) {
					user.setType("weibo");
				} else if (type.equals("QQ")) {
					user.setType("qq");
				} else {
					user.setType("weixinweb");
				}
				user.setToken(jsonData.getString("token"));
				user.setSex(sex);
				user.setPassWord("123456");
				user.setImPass(jsonData.getString("im_password"));
				db.save(user);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}

	/**
	 * 用户信息详情（雇主/威客）
	 * 
	 * @param context
	 * @return
	 */
	public static Map<String, Object> getUserInfo(Context context) {
		Map<String, Object> map = new HashMap<String, Object>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/getUserInfo?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));
				map.put("nickname", jsondata.getString("nickname"));
				map.put("avatar", jsondata.getString("avatar"));
				map.put("isRealName", jsondata.getString("isRealName"));
				map.put("avatar", jsondata.getString("avatar"));
				map.put("name", jsondata.getString("name"));
				map.put("tag", jsondata.getString("tag"));
				if (!StrFormat.formatStr(jsondata.getString("qq"))) {
					map.put("qq", "");
				} else {
					map.put("qq", jsondata.getString("qq"));
				}
				if (!StrFormat.formatStr(jsondata.getString("wechat"))) {
					map.put("wechat", "");
				} else {
					map.put("wechat", jsondata.getString("wechat"));
				}
			} else {
				Toast.makeText(context, jsonObject.getString("message"),
						Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 退出登录
	 * 
	 * @param context
	 */
	public static void userLoginOut(Context context) {
		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/loginOut?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				db.deleteById(UserBean.class, users.get(0).getId());
				Toast.makeText(context, "退出成功", Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, jsonObject.getString("message"),
						Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 修改用户信息
	 * 
	 * @param strQQ
	 * @param strWeixin
	 * @param strImage
	 * @param context
	 */
	public static String updateUserInfo(String strQQ, String strWeixin,
			String strImage, Context context) {
		String str = "";
		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/updateUserInfo";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		try {
			MultipartEntity multipart = new MultipartEntity();
			if (StrFormat.formatStr(strImage)) {
				File file1 = new File(strImage);
				multipart.addPart("avatar", new FileBody(file1));
			}

			multipart.addPart("qq",
					new StringBody(strQQ, Charset.forName("UTF-8")));
			multipart.addPart("wechat",
					new StringBody(strWeixin, Charset.forName("UTF-8")));
			multipart.addPart("token", new StringBody(users.get(0).getToken(),
					Charset.forName("UTF-8")));

			String strJson = httpUtils.httpPost(urlString, multipart);
			JSONObject jsonObject = new JSONObject(strJson);

			str = jsonObject.getString("message");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return str;
	}

	/**
	 * 钱包余额
	 * 
	 * @param context
	 * @return
	 */
	public static String getBalance(Context context) {
		String strBalance = null;

		String urlString = ConfigInc.getServiceAdress(context) + "pay/balance?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject info = new JSONObject(jsonObject.getString("data"));
				strBalance = info.getString("balance");

			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strBalance;
	}

	/**
	 * 钱包余额和每日提现金额
	 * 
	 * @param context
	 * @return
	 */
	public static Map<String, String> getMoneyConfig(Context context) {
		Map<String, String> map = new HashMap<>();

		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/moneyConfig?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject info = new JSONObject(jsonObject.getString("data"));
				map.put("balance", info.getString("balance"));
				map.put("withdrawals", info.getString("withdrawals"));

			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 已认证的银行卡信息列表
	 * 
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getBankAccount(
			Context context) {
		ArrayList<HashMap<String, Object>> bankList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "pay/bankAccount?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			JSONArray jsonArray = jsonObject.getJSONArray("data");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				if (jsonArray.length() > 0) {
					for (int i = 0; i < jsonArray.length(); i++) {
						HashMap<String, Object> map = new HashMap<String, Object>();
						JSONObject itemJsonObject = jsonArray.optJSONObject(i);

						map.put("id", itemJsonObject.getString("id"));
						map.put("uid", itemJsonObject.getString("uid"));
						map.put("username",
								itemJsonObject.getString("username"));
						if (itemJsonObject.getString("realname").equals("null")) {
							map.put("realname", "");
						} else {
							map.put("realname",
									itemJsonObject.getString("realname"));
						}

						map.put("bank_name",
								itemJsonObject.getString("bank_name"));
						map.put("bank_img",
								itemJsonObject.getString("bank_img"));
						map.put("account",
								itemJsonObject.getString("bank_account"));
						map.put("deposit_name",
								"(" + itemJsonObject.getString("deposit_name")
										+ ")");
						map.put("status", itemJsonObject.getString("status"));

						bankList.add(map);
					}
				} else {
					Toast.makeText(context, "无数据", Toast.LENGTH_SHORT).show();
				}
			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bankList;
	}

	/**
	 * 提现
	 * 
	 * @param strCash
	 * @param strType
	 * @param strAccount
	 * @param strPassword
	 * @param context
	 */
	public static String[] postCashOut(String strCash, String strType,
			String strAccount, String strPassword, Context context) {
		String str[] = new String[2];
		String urlString = ConfigInc.getServiceAdress(context) + "pay/cashOut";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("token", users.get(0).getToken()));
		params.add(new BasicNameValuePair("cash", strCash));
		params.add(new BasicNameValuePair("cashout_type", strType));
		params.add(new BasicNameValuePair("cashout_account", strAccount));
		params.add(new BasicNameValuePair("alternate_password", strPassword));

		try {
			String strJson = httpUtils.executeRequest(urlString, params);
			JSONObject jsonObject = new JSONObject(strJson);

			str[0] = jsonObject.getString("code");
			str[1] = jsonObject.getString("message");

		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}

	/**
	 * 已认证的支付宝信息列表
	 * 
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getAlipayAccount(
			Context context) {
		ArrayList<HashMap<String, Object>> bankList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "pay/alipayAccount?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONArray jsonArray = jsonObject.getJSONArray("data");
				if (jsonArray.length() > 0) {
					for (int i = 0; i < jsonArray.length(); i++) {
						HashMap<String, Object> map = new HashMap<String, Object>();
						JSONObject itemJsonObject = jsonArray.optJSONObject(i);

						map.put("id", itemJsonObject.getString("id"));
						map.put("uid", itemJsonObject.getString("uid"));
						map.put("username",
								itemJsonObject.getString("username"));
						map.put("realname",
								itemJsonObject.getString("realname"));
						map.put("alipay_name",
								itemJsonObject.getString("alipay_name"));
						map.put("account",
								itemJsonObject.getString("alipay_account"));

						map.put("account11", StrFormat.getStarString(
								itemJsonObject.getString("alipay_account"), 4,
								0));

						map.put("status", itemJsonObject.getString("status"));

						bankList.add(map);
					}
				} else {
					Toast.makeText(context, "无数据", Toast.LENGTH_SHORT).show();
				}
			} else {
				Toast.makeText(context, "暂无已认证的支付宝信息", Toast.LENGTH_SHORT)
						.show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bankList;
	}

	/**
	 * 财务流水
	 * 
	 * @param page
	 * @param timeStatus
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getFinanceList(int page,
			int timeStatus, Context context) {
		ArrayList<HashMap<String, Object>> bankList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "pay/financeList?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", "" + users.get(0).getToken());
		params.put("timeStatus", "" + timeStatus);
		params.put("page", "" + page);

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));

				JSONArray jsonArray = jsondata.getJSONArray("finance");
				if (jsonArray.length() > 0) {
					for (int i = 0; i < jsonArray.length(); i++) {
						HashMap<String, Object> map = new HashMap<String, Object>();
						JSONObject itemJsonObject = jsonArray.optJSONObject(i);

						map.put("id", itemJsonObject.getString("id"));
						map.put("action", itemJsonObject.getString("action"));// 收支行为(1:发布任务
																				// 2:接受任务
																				// 3:用户充值
																				// 4:用户提现
																				// 5:购买增值服务
																				// 6:购买用户商品
																				// 7:任务失败退款
																				// 8:提现失败退款)
						map.put("pay_type",
								itemJsonObject.getString("pay_type"));// 支付渠道类型(1:表示余额
																		// 2:表示支付宝
																		// 3:表示微信
																		// 4:表示银联)
						map.put("pay_account",
								itemJsonObject.getString("pay_account"));// 支付账号
						map.put("pay_code",
								itemJsonObject.getString("pay_code"));// 支付渠道流水号
						map.put("cash", itemJsonObject.getString("cash"));// 金额

						map.put("uid", itemJsonObject.getString("uid"));

						map.put("created_at",
								itemJsonObject.getString("created_at"));// 创建时间

						bankList.add(map);
					}
				}
			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bankList;
	}

	/**
	 * 关于我们
	 * 
	 * @param context
	 * @return
	 */
	public static Map<String, String> getAboutUs(Context context) {
		Map<String, String> map = new HashMap<String, String>();

		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/aboutUs?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);

			JSONObject jsonObject = new JSONObject(strJson);
			String resString = jsonObject.getString("code");

			map.put("code", jsonObject.getString("code"));
			map.put("message", jsonObject.getString("message"));

			// 对返回的数据进行判断
			if (resString.equals("1000")) {
				if (jsonObject.getString("data").equals("[]")) {
					map.put("title", "");
					map.put("content", "");
				} else {
					JSONObject jsondata = jsonObject.getJSONObject("data");
					map.put("title", jsondata.getString("title"));
					map.put("content", jsondata.getString("content"));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	// 威客承接任务统计
	public static Map<String, String> myAcceptCount(String strType,
			Context context) {
		Map<String, String> map = new HashMap<String, String>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/myAcceptCount?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", users.get(0).getToken());
		params.put("type", strType);
		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));

				map.put("bid", jsondata.getString("bid"));
				map.put("choose", jsondata.getString("choose"));
				map.put("work_in", jsondata.getString("work_in"));
				map.put("comment", jsondata.getString("comment"));
				map.put("success", jsondata.getString("success"));
				map.put("right", jsondata.getString("right"));
				map.put("failure", jsondata.getString("failure"));
				map.put("verify", "0");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	// 雇主发布的任务数量统计
	public static Map<String, String> indexCount(String strType, Context context) {
		Map<String, String> map = new HashMap<String, String>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/indexCount?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", users.get(0).getToken());
		params.put("type", strType);
		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));

				map.put("bid", jsondata.getString("bid"));
				map.put("choose", jsondata.getString("choose"));
				map.put("work_in", jsondata.getString("work_in"));
				map.put("comment", jsondata.getString("comment"));
				map.put("success", jsondata.getString("success"));
				map.put("right", jsondata.getString("right"));
				map.put("failure", jsondata.getString("failure"));
				map.put("verify", jsondata.getString("verify"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	// 我卖出的作品或服务雇佣的数量统计
	public static Map<String, String> mySaleGoodsCount(String strType,
			Context context) {
		Map<String, String> map = new HashMap<String, String>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/mySaleGoodsCount?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", users.get(0).getToken());
		params.put("type", strType);
		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));

				if (strType.equals("1")) {
					map.put("all", jsondata.getString("all"));
					map.put("is_pay", jsondata.getString("is_pay"));
					map.put("finish", jsondata.getString("finish"));
					map.put("other", jsondata.getString("other"));
				} else {
					map.put("all", jsondata.getString("all"));
					map.put("is_wait", jsondata.getString("is_wait"));
					map.put("working", jsondata.getString("working"));
					map.put("finish", jsondata.getString("finish"));
					map.put("other", jsondata.getString("other"));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	// 我购买的作品或服务雇佣数量统计
	public static Map<String, String> myBuyGoodsCount(String strType,
			Context context) {
		Map<String, String> map = new HashMap<String, String>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/myBuyGoodsCount?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", users.get(0).getToken());
		params.put("type", strType);
		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));

				if (strType.equals("1")) {
					map.put("all", jsondata.getString("all"));
					map.put("is_pay", jsondata.getString("is_pay"));
					map.put("finish", jsondata.getString("finish"));
					map.put("other", jsondata.getString("other"));
				} else {
					map.put("all", jsondata.getString("all"));
					map.put("is_wait", jsondata.getString("is_wait"));
					map.put("working", jsondata.getString("working"));
					map.put("finish", jsondata.getString("finish"));
					map.put("other", jsondata.getString("other"));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

}
